package eagle.im.server;

import eagle.im.proto.LoginModel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * @Program : eagle-im
 * @ClassName : ServerHandler
 * @Description :
 * @Date: 2021-12-20 18:18
 * @Version : 1.0
 */
public class ServerHandler extends SimpleChannelInboundHandler<LoginModel.LoginInfo> {

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("连接上一个客户端。。。。");
    }

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, LoginModel.LoginInfo info) throws Exception {

        System.out.println(info.getName());

        System.out.println(info.getPassword());

        System.out.println(info.getType());

        System.out.println(info.getDesc());

        LoginModel.LoginInfo infoToClient = LoginModel.LoginInfo.newBuilder()
                .setName("client : " + channelHandlerContext.channel().localAddress().toString())
                .setType(10)
                .setPassword("server to client password")
                .setDesc("aaaaaaaaaaaaaaaa").build()
                ;
       // StudentInfo.Student serverToClient= StudentInfo.Student.newBuilder();
        channelHandlerContext.channel().writeAndFlush(infoToClient);
    }

}
